# coding: utf-8
from sklearn.neighbors import KNeighborsClassifier
import matplotlib.pyplot as plt
#import matplotlib
#matplotlib.use('TkAgg')
# 1: 构造数据集
x = [[1],[2],[3],[4]]
y = [0,0,1,1]

# 2: 可视化表达
plt.figure(figsize=(20,8),dpi=100)
plt.plot(x,y)

# 3: 实例化一个估计器对象
estimator = KNeighborsClassifier(n_neighbors=3)

# 4: 模型训练
estimator.fit(x,y)

# 5： 数据预测
ret = estimator.predict([[2.51]])
plt.scatter(2.51,ret[0],color='red')
ret2 = estimator.predict([[2.52]])
plt.scatter(2.52,ret2[0],color='green')

plt.show()